class MainView extends eui.Component {
  background: eui.Image; // 背景
  btn_menu_1: eui.Button; // 按钮

  constructor() {
    super();
    // 绑定皮肤，也可以在default.thm.json添加配置进行绑定
    this.skinName = "resource/my_skins/MainView.exml";
    const mainStage = egret.MainContext.instance.stage;
    mainStage.addChild(this);
  }

  protected childrenCreated(): void {
    super.childrenCreated();
    this.btn_menu_1.addEventListener(
      'touchTap',
      function() {
        console.log('按钮点击');
      },
      this
    )
    this.background.addEventListener(
      'touchTap',
      this.touchAttack,
      this
    )
  }

  /**背景点击执行方法 */
  private touchAttack(event: egret.TouchEvent): void {
    // 播放MC动画
    ClickMC.show('clickEffect_1', event.stageX, event.stageY)
    
    let damageText = ObjectPool.getObj("damageFont") as egret.BitmapText;
    if (!damageText) {
      damageText = new egret.BitmapText();
      damageText.font = RES.getRes("damageFont_fnt");
      damageText.letterSpacing = -2;
    }
    damageText.text = '12.3Abc';
    damageText.x = event.stageX - damageText.width / 2;
    damageText.y = event.stageY - damageText.height;
    this.addChild(damageText);
    egret.Tween.get(damageText).to({x: damageText.x - 30, y: damageText.y - 70}, 400).call(function() {
      damageText.parent.removeChild(damageText);
      ObjectPool.cache("damageFont", damageText)
    })
  }
}